(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 8.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[     87726,       2010]
NotebookOptionsPosition[     82871,       1899]
NotebookOutlinePosition[     83361,       1918]
CellTagsIndexPosition[     83318,       1915]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell["\<\
*****************************************************************************
*   Notebook written by: Fabian St\[ODoubleDot]ckl      \t\t                  *
*   E-Mail: fabian-stoeckl@hotmail.com                                   * 
*****************************************************************************
******************************************************************************\
******************************************************************************\
******
*    This notebook uses the Package \"TransformedFit\[CloseCurlyDoubleQuote] \
written by Oleksandr R. (https://github.com/oleksandrr/TransformedFit)    *
*    Information: \
https://mathematica.stackexchange.com/questions/2784/fitting-fractional-\
complex-data-with-nonlinearmodelfit     * 
******************************************************************************\
******************************************************************************\
******\
\>", "Text",
 CellChangeTimes->{{3.803296525642475*^9, 3.803296606317089*^9}, {
  3.8033017724235735`*^9, 3.8033017865893836`*^9}, {3.803312053691663*^9, 
  3.8033122329989185`*^9}, {3.840725380535838*^9, 
  3.8407253878135557`*^9}},ExpressionUUID->"4ed25a2f-0f52-4f98-a11d-\
10e5720b080c"],

Cell[BoxData[{
 RowBox[{"ClearAll", "[", "\"\<Global`*\>\"", "]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"SetDirectory", "[", 
   RowBox[{"NotebookDirectory", "[", "]"}], "]"}], ";"}]}], "Input",
 CellChangeTimes->{{3.7905163245296135`*^9, 3.7905163620487595`*^9}, {
  3.7926688210939684`*^9, 3.7926688450787497`*^9}, {3.792674067222597*^9, 
  3.7926741434699583`*^9}, {3.792674946898912*^9, 3.792674951098152*^9}, {
  3.7926750283215694`*^9, 3.792675056518182*^9}, {3.7926751056609926`*^9, 
  3.792675162891266*^9}, {3.792675215506275*^9, 3.792675237233518*^9}, {
  3.792677132268908*^9, 3.7926771660318394`*^9}, {3.7974079290942802`*^9, 
  3.7974080103059254`*^9}, {3.803296313095318*^9, 3.803296420885483*^9}, {
  3.803296458793651*^9, 
  3.8032964899214315`*^9}},ExpressionUUID->"3027b843-7e91-4b81-b7d0-\
b4a81223ddc3"],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"BeginPackage", "[", "\"\<TransformedFit`\>\"", "]"}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"ClearAll", "[", "TransformedParameter", "]"}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"SetAttributes", "[", 
    RowBox[{"TransformedParameter", ",", "HoldRest"}], "]"}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"Unprotect", "[", "TransformedFit", "]"}], ";", 
   RowBox[{"ClearAll", "[", "TransformedFit", "]"}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"Unprotect", "[", "ComplexFit", "]"}], ";", 
   RowBox[{"ClearAll", "[", "ComplexFit", "]"}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"Begin", "[", "\"\<`Private`\>\"", "]"}], ";"}], "\n", 
  "\[IndentingNewLine]", 
  RowBox[{"(*", " ", 
   RowBox[{
   "Transform", " ", "numeric", " ", "quantities", " ", "rather", " ", "than",
     " ", "renaming", " ", "them"}], " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"TransformedParameter", "[", 
     RowBox[{"t_", ",", 
      RowBox[{"num_", "?", "NumericQ"}]}], "]"}], ":=", 
    RowBox[{"t", "[", "num", "]"}]}], ";"}], "\[IndentingNewLine]", 
  "\[IndentingNewLine]", 
  RowBox[{"(*", " ", 
   RowBox[{
   "Generate", " ", "unique", " ", "symbols", " ", "for", " ", "each", " ", 
    "transformed", " ", 
    RowBox[{"parameter", " ", "--"}], " ", "this", " ", "avoids", " ", 
    "difficulties", "\[IndentingNewLine]", "caused", " ", "by", " ", 
    "overzealous", " ", "common", " ", "subexpression", " ", "elimination", 
    " ", "when", " ", "the", " ", "models", " ", "are", " ", "compiled"}], 
   " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"tp", ":", 
     RowBox[{"TransformedParameter", "[", 
      RowBox[{"t_", ",", "p_"}], "]"}]}], ":=", 
    RowBox[{"tp", "=", "\[IndentingNewLine]", 
     RowBox[{"With", "[", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"sym", "=", 
         RowBox[{"Unique", "[", 
          RowBox[{
          "\"\<TransformedFit`TransformedParameter$\>\"", ",", "Temporary"}], 
          "]"}]}], "}"}], ",", "\[IndentingNewLine]", 
       RowBox[{"(*", " ", 
        RowBox[{
        "Unset", " ", "memo", " ", "when", " ", "cleared", " ", "to", " ", 
         "facilitate", " ", "garbage", " ", "collection"}], " ", "*)"}], 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"sym", "/:", 
         RowBox[{"clear", ":", 
          RowBox[{
           RowBox[{"(", 
            RowBox[{"Clear", "|", "ClearAll", "|", "Remove"}], ")"}], "[", 
           RowBox[{"___", ",", "sym", ",", "___"}], "]"}]}], ":=", 
         "\[IndentingNewLine]", 
         RowBox[{"clear", "/;", 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"tp", "=."}], ";", "True"}], ")"}]}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"(*", " ", 
         RowBox[{
         "Display", " ", "in", " ", "a", " ", "form", " ", "that", " ", 
          "makes", " ", "clear", " ", "the", " ", "parameter", " ", "and", 
          " ", "transformation", " ", "represented"}], " ", "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{"sym", "/:", 
         RowBox[{"MakeBoxes", "[", 
          RowBox[{"sym", ",", "form_"}], "]"}], ":=", "\[IndentingNewLine]", 
         RowBox[{"With", "[", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"boxes", "=", 
             RowBox[{"MakeBoxes", "[", 
              RowBox[{
               RowBox[{"t", "[", "p", "]"}], ",", "form"}], "]"}]}], "}"}], 
           ",", "\[IndentingNewLine]", 
           RowBox[{"InterpretationBox", "[", 
            RowBox[{"boxes", ",", "sym"}], "]"}]}], "\[IndentingNewLine]", 
          "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        "sym"}]}], "\[IndentingNewLine]", "]"}]}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"ClearAll", "[", "$FitFunctions", "]"}], ";"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"$FitFunctions", "=", 
    RowBox[{"If", "[", 
     RowBox[{
      RowBox[{"$VersionNumber", "\[GreaterEqual]", "7"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"{", 
       RowBox[{"FindFit", ",", "NonlinearModelFit"}], "}"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"{", "FindFit", "}"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"Options", "[", "TransformedFit", "]"}], "=", 
    RowBox[{"{", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"\"\<FitFunction\>\"", "\[Rule]", 
       RowBox[{"First", "[", "$FitFunctions", "]"}]}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"\"\<Transformation\>\"", "\[Rule]", "Identity"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"\"\<ParameterTransformation\>\"", "\[Rule]", "Identity"}], ",",
       "\[IndentingNewLine]", 
      RowBox[{"\"\<Hold\>\"", "\[Rule]", "False"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"\"\<Backsubstitution\>\"", "\[Rule]", "False"}]}], 
     "\[IndentingNewLine]", "}"}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"TransformedFit", "::", "cons"}], "=", 
    "\"\<The constraint(s), `1`, should be given in terms of the transformed \
parameters only.\>\""}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"TransformedFit", "[", "\[IndentingNewLine]", 
      RowBox[{"data_", ",", 
       RowBox[{"{", 
        RowBox[{"model_", ",", 
         RowBox[{
          RowBox[{"{", "cons__", "}"}], "|", "cons__"}]}], "}"}], ",", 
       "pars_", ",", "vars_", ",", "\[IndentingNewLine]", "opts___"}], 
      "\[IndentingNewLine]", "]"}], "/;", 
     RowBox[{"Internal`DependsOnQ", "[", 
      RowBox[{
       RowBox[{"{", "cons", "}"}], ",", 
       RowBox[{"Replace", "[", 
        RowBox[{"pars", ",", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"p_", ",", 
            RowBox[{"_", "?", "NumericQ"}]}], "}"}], "\[RuleDelayed]", "p"}], 
         ",", 
         RowBox[{"{", "1", "}"}]}], "]"}]}], "]"}]}], ":=", 
    "\[IndentingNewLine]", 
    RowBox[{"Message", "[", 
     RowBox[{
      RowBox[{"TransformedFit", "::", "cons"}], ",", 
      RowBox[{"{", "cons", "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
  "\[IndentingNewLine]", 
  RowBox[{"(*", " ", 
   RowBox[{
   "Deal", " ", "with", " ", "data", " ", "given", " ", "as", " ", "ordinate",
     " ", "values", " ", "only"}], " ", "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"TransformedFit", "[", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"data_", "?", "VectorQ"}], ",", "model_", ",", "pars_", ",", 
      "vars_", ",", "\[IndentingNewLine]", 
      RowBox[{"opts", ":", 
       RowBox[{"OptionsPattern", "[", 
        RowBox[{"{", 
         RowBox[{"TransformedFit", ",", 
          RowBox[{"Sequence", "@@", "$FitFunctions"}]}], "}"}], "]"}]}]}], 
     "\[IndentingNewLine]", "]"}], ":=", "\[IndentingNewLine]", 
    RowBox[{"TransformedFit", "[", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"Transpose", "[", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Range", "@", 
          RowBox[{"Length", "[", "data", "]"}]}], ",", "data"}], "}"}], "]"}],
       ",", "model", ",", "pars", ",", "vars", ",", "\[IndentingNewLine]", 
      "opts"}], "\[IndentingNewLine]", "]"}]}], ";"}], 
  "\n"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"TransformedFit", "[", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"data_", "?", "MatrixQ"}], ",", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"model_", ",", "cons__"}], "}"}], "|", 
       RowBox[{"{", "model_", "}"}], "|", "model_"}], ",", "pars_", ",", 
      "vars_", ",", "\[IndentingNewLine]", 
      RowBox[{"opts", ":", 
       RowBox[{"OptionsPattern", "[", 
        RowBox[{"{", 
         RowBox[{"TransformedFit", ",", 
          RowBox[{"Sequence", "@@", "$FitFunctions"}]}], "}"}], "]"}]}]}], 
     "\[IndentingNewLine]", "]"}], ":=", "\[IndentingNewLine]", 
    RowBox[{"With", "[", 
     RowBox[{
      RowBox[{"{", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"fitFunction", "=", 
         RowBox[{
          RowBox[{
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{"MemberQ", "[", 
              RowBox[{"$FitFunctions", ",", "#"}], "]"}], ",", "#", ",", 
             RowBox[{"First", "[", "$FitFunctions", "]"}]}], "]"}], "&"}], 
          " ", "@", " ", 
          RowBox[{"OptionValue", "[", "\"\<FitFunction\>\"", "]"}]}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"transformations", "=", 
         RowBox[{
          RowBox[{"List", "@", 
           RowBox[{"OptionValue", "[", "\"\<Transformation\>\"", "]"}]}], "~",
           "Flatten", "~", "1"}]}]}], "\[IndentingNewLine]", "}"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"Block", "[", 
       RowBox[{
        RowBox[{"{", "\[IndentingNewLine]", 
         RowBox[{
         "transformedData", ",", "\[IndentingNewLine]", 
          "transformedParameters", ",", "unusedParameterMask", ",", 
          "parameterRules", ",", "\[IndentingNewLine]", "transformedModel", 
          ",", "i", ",", "\[IndentingNewLine]", "fitResult"}], 
         "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
        RowBox[{"(*", " ", 
         RowBox[{"TRANSFORM", " ", "DATA"}], " ", "*)"}], 
        "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"With", "[", 
          RowBox[{
           RowBox[{"{", "\[IndentingNewLine]", 
            RowBox[{
             RowBox[{"abscissae", "=", 
              RowBox[{"Take", "[", 
               RowBox[{"data", ",", "All", ",", 
                RowBox[{"{", 
                 RowBox[{"1", ",", 
                  RowBox[{"-", "2"}]}], "}"}]}], "]"}]}], ",", 
             "\[IndentingNewLine]", 
             RowBox[{"ordinates", "=", 
              RowBox[{"Take", "[", 
               RowBox[{"data", ",", "All", ",", 
                RowBox[{"{", 
                 RowBox[{"-", "1"}], "}"}]}], "]"}]}]}], 
            "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
           RowBox[{
            RowBox[{"transformedData", "=", 
             RowBox[{
              RowBox[{"{", "\[IndentingNewLine]", 
               RowBox[{
                RowBox[{
                 RowBox[{"ConstantArray", "[", 
                  RowBox[{
                   RowBox[{"Range", "@", 
                    RowBox[{"Length", "[", "transformations", "]"}]}], ",", 
                   RowBox[{"{", 
                    RowBox[{
                    RowBox[{"Length", "[", "abscissae", "]"}], ",", "1"}], 
                    "}"}]}], "]"}], "~", "Transpose", "~", 
                 RowBox[{"{", 
                  RowBox[{"2", ",", "3", ",", "1"}], "}"}]}], ",", 
                "\[IndentingNewLine]", 
                RowBox[{"ConstantArray", "[", 
                 RowBox[{"abscissae", ",", 
                  RowBox[{"Length", "[", "transformations", "]"}]}], "]"}], 
                ",", "\[IndentingNewLine]", 
                RowBox[{"Through", "@", 
                 RowBox[{"transformations", "[", "ordinates", "]"}]}]}], 
               "\[IndentingNewLine]", "}"}], "~", "Flatten", "~", 
              RowBox[{"{", 
               RowBox[{
                RowBox[{"{", 
                 RowBox[{"2", ",", "3"}], "}"}], ",", 
                RowBox[{"{", 
                 RowBox[{"1", ",", "4"}], "}"}]}], "}"}]}]}], ";"}]}], 
          "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", 
         "\[IndentingNewLine]", 
         RowBox[{"(*", " ", 
          RowBox[{"TRANSFORM", " ", "PARAMETERS"}], " ", "*)"}], 
         "\[IndentingNewLine]", 
         RowBox[{"transformedParameters", "=", 
          RowBox[{
           RowBox[{"Outer", "[", "\[IndentingNewLine]", 
            RowBox[{
            "TransformedParameter", ",", "\[IndentingNewLine]", 
             "transformations", ",", 
             RowBox[{
              RowBox[{"{", "pars", "}"}], "~", "Flatten", "~", "1"}]}], 
            "\[IndentingNewLine]", "]"}], "//", "Transpose"}]}], ";", 
         "\[IndentingNewLine]", 
         RowBox[{"With", "[", 
          RowBox[{
           RowBox[{"{", "\[IndentingNewLine]", 
            RowBox[{"(*", " ", 
             RowBox[{
             "Original", " ", "and", " ", "transformed", " ", "parameters", 
              " ", "without", " ", "initial", " ", "guesses"}], " ", "*)"}], 
            "\[IndentingNewLine]", 
            RowBox[{
             RowBox[{"originalParameterNames", "=", 
              RowBox[{"Replace", "[", 
               RowBox[{"pars", ",", 
                RowBox[{
                 RowBox[{"{", 
                  RowBox[{"p_", ",", 
                   RowBox[{"_", "?", "NumericQ"}]}], "}"}], "\[RuleDelayed]", 
                 "p"}], ",", 
                RowBox[{"{", "1", "}"}]}], "]"}]}], ",", 
             "\[IndentingNewLine]", 
             RowBox[{"transformedParameterNames", "=", 
              RowBox[{"Replace", "[", 
               RowBox[{"transformedParameters", ",", 
                RowBox[{
                 RowBox[{"{", 
                  RowBox[{"p_", ",", 
                   RowBox[{"_", "?", "NumericQ"}]}], "}"}], "\[RuleDelayed]", 
                 "p"}], ",", 
                RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", 
            "}"}], ",", "\[IndentingNewLine]", 
           RowBox[{
            RowBox[{"With", "[", 
             RowBox[{
              RowBox[{"{", "\[IndentingNewLine]", 
               RowBox[{"(*", " ", 
                RowBox[{
                "Representations", " ", "of", " ", "the", " ", "original", 
                 " ", "parameters", " ", "in", " ", "terms", " ", "of", " ", 
                 "their", " ", "transformations"}], " ", "*)"}], 
               "\[IndentingNewLine]", 
               RowBox[{"parameterRepresentations", "=", 
                RowBox[{
                 RowBox[{
                 "OptionValue", "[", "\"\<ParameterTransformation\>\"", "]"}],
                  "@@@", "transformedParameterNames"}]}], 
               "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
              RowBox[{
               RowBox[{"unusedParameterMask", "=", 
                RowBox[{"MapThread", "[", "\[IndentingNewLine]", 
                 RowBox[{
                  RowBox[{"Composition", "[", 
                   RowBox[{"Thread", ",", "Unevaluated", ",", "FreeQ"}], 
                   "]"}], ",", "\[IndentingNewLine]", 
                  RowBox[{"{", 
                   RowBox[{
                   "parameterRepresentations", ",", 
                    "transformedParameterNames"}], "}"}]}], 
                 "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", 
               RowBox[{"Clear", "@@", 
                RowBox[{"Flatten", "@", 
                 RowBox[{"Pick", "[", 
                  RowBox[{
                  "transformedParameterNames", ",", "unusedParameterMask"}], 
                  "]"}]}]}], ";", "\[IndentingNewLine]", 
               RowBox[{"parameterRules", "=", 
                RowBox[{"Thread", "[", 
                 RowBox[{
                 "originalParameterNames", "\[Rule]", 
                  "parameterRepresentations"}], "]"}]}], ";"}]}], 
             "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", 
          "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
         RowBox[{"(*", " ", 
          RowBox[{"TRANSFORM", " ", "MODEL"}], " ", "*)"}], 
         "\[IndentingNewLine]", 
         RowBox[{"With", "[", 
          RowBox[{
           RowBox[{"{", "\[IndentingNewLine]", 
            RowBox[{
             RowBox[{"reparameterizedModel", "=", 
              RowBox[{"model", "/.", "parameterRules"}]}], ",", 
             "\[IndentingNewLine]", 
             RowBox[{"KroneckerDelta", "=", 
              RowBox[{
               RowBox[{"If", "[", 
                RowBox[{
                 RowBox[{"Equal", "[", "##", "]"}], ",", "1", ",", "0"}], 
                "]"}], "&"}]}]}], " ", 
            RowBox[{"(*", " ", "compilable", " ", "*)"}], 
            "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
           RowBox[{
            RowBox[{"transformedModel", "=", 
             RowBox[{"Inner", "[", "\[IndentingNewLine]", 
              RowBox[{
               RowBox[{
                RowBox[{
                 RowBox[{"#1", "[", "reparameterizedModel", "]"}], 
                 RowBox[{"KroneckerDelta", "[", 
                  RowBox[{"i", ",", "#2"}], "]"}]}], "&"}], ",", 
               "\[IndentingNewLine]", "transformations", ",", 
               RowBox[{"Range", "@", 
                RowBox[{"Length", "[", "transformations", "]"}]}]}], 
              "\[IndentingNewLine]", "]"}]}], ";"}]}], "\[IndentingNewLine]", 
          "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
         RowBox[{"(*", " ", 
          RowBox[{"PERFORM", " ", "FIT"}], " ", "*)"}], "\[IndentingNewLine]", 
         RowBox[{"fitResult", "=", 
          RowBox[{
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{"TrueQ", "@", 
              RowBox[{"OptionValue", "[", "\"\<Hold\>\"", "]"}]}], ",", 
             RowBox[{"Composition", "[", 
              RowBox[{"Return", ",", "Hold", ",", "fitFunction"}], "]"}], ",",
              "fitFunction"}], "]"}], "[", "\[IndentingNewLine]", 
           RowBox[{"transformedData", ",", "\[IndentingNewLine]", 
            RowBox[{"{", 
             RowBox[{"transformedModel", ",", "cons"}], "}"}], ",", 
            "\[IndentingNewLine]", 
            RowBox[{
             RowBox[{"Pick", "[", 
              RowBox[{
              "transformedParameters", ",", "unusedParameterMask", ",", 
               "False"}], "]"}], "~", "Flatten", "~", "1"}], ",", 
            "\[IndentingNewLine]", 
            RowBox[{
             RowBox[{"{", 
              RowBox[{"i", ",", "vars"}], "}"}], "~", "Flatten", "~", "1"}], 
            ",", "\[IndentingNewLine]", 
            RowBox[{"FilterRules", "[", 
             RowBox[{
              RowBox[{"{", "opts", "}"}], ",", 
              RowBox[{"Options", "[", "fitFunction", "]"}]}], "]"}]}], 
           "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", 
         "\[IndentingNewLine]", 
         RowBox[{"(*", " ", 
          RowBox[{"POSTPROCESS", " ", "RESULT"}], " ", "*)"}], 
         "\[IndentingNewLine]", 
         RowBox[{"If", "[", 
          RowBox[{
           RowBox[{
            RowBox[{"TrueQ", "@", 
             RowBox[{"OptionValue", "[", "\"\<Backsubstitution\>\"", "]"}]}], 
            "&&", 
            RowBox[{"fitFunction", "===", "FindFit"}]}], ",", 
           "\[IndentingNewLine]", 
           RowBox[{"parameterRules", "/.", "fitResult"}], ",", 
           "\[IndentingNewLine]", "fitResult"}], "\[IndentingNewLine]", 
          "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", 
     "]"}]}], ";"}], "\n"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"Protect", "[", "TransformedFit", "]"}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"ClearAll", "[", "coordinateSystemRules", "]"}], ";"}], 
  "\[IndentingNewLine]", 
  RowBox[{"(*", " ", 
   RowBox[{"Default", " ", "to", " ", "Cartesian", " ", "coordinates"}], " ", 
   "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"coordinateSystemRules", "[", 
    RowBox[{"\"\<Cartesian\>\"", "|", "_"}], "]"}], "=", 
   RowBox[{"Sequence", "[", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"\"\<Transformation\>\"", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{"Re", ",", "Im"}], "}"}]}], ",", "\[IndentingNewLine]", 
     RowBox[{"\"\<ParameterTransformation\>\"", "\[Rule]", 
      RowBox[{"(", 
       RowBox[{
        RowBox[{"#1", "+", 
         RowBox[{"I", " ", "#2"}]}], "&"}], ")"}]}], ",", 
     "\[IndentingNewLine]", 
     RowBox[{"\"\<Backsubstitution\>\"", "\[Rule]", "True"}]}], 
    "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"coordinateSystemRules", "[", "\"\<Polar\>\"", "]"}], "=", 
   RowBox[{"Sequence", "[", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"\"\<Transformation\>\"", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{"Abs", ",", "Arg"}], "}"}]}], ",", "\[IndentingNewLine]", 
     RowBox[{"\"\<ParameterTransformation\>\"", "\[Rule]", 
      RowBox[{"(", 
       RowBox[{
        RowBox[{"#1", 
         RowBox[{"Exp", "[", 
          RowBox[{"I", "#2"}], "]"}]}], "&"}], ")"}]}], ",", 
     "\[IndentingNewLine]", 
     RowBox[{"\"\<Backsubstitution\>\"", "\[Rule]", "False"}]}], 
    "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"coordinateSystemRules", "[", "\"\<Real\>\"", "]"}], "=", 
   RowBox[{"Sequence", "[", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"\"\<Transformation\>\"", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{"Re", ",", "Im"}], "}"}]}], ",", "\[IndentingNewLine]", 
     RowBox[{"\"\<ParameterTransformation\>\"", "\[Rule]", 
      RowBox[{"(", 
       RowBox[{"#1", "&"}], ")"}]}], ",", "\[IndentingNewLine]", 
     RowBox[{"\"\<Backsubstitution\>\"", "\[Rule]", "True"}]}], 
    "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"coordinateSystemRules", "[", "\"\<Imaginary\>\"", "]"}], "=", 
    RowBox[{"Sequence", "[", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"\"\<Transformation\>\"", "\[Rule]", 
       RowBox[{"{", 
        RowBox[{"Re", ",", "Im"}], "}"}]}], ",", "\[IndentingNewLine]", 
      RowBox[{"\"\<ParameterTransformation\>\"", "\[Rule]", 
       RowBox[{"(", 
        RowBox[{
         RowBox[{"I", " ", "#2"}], "&"}], ")"}]}], ",", "\[IndentingNewLine]", 
      RowBox[{"\"\<Backsubstitution\>\"", "\[Rule]", "True"}]}], 
     "\[IndentingNewLine]", "]"}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"Options", "[", "ComplexFit", "]"}], "=", 
    RowBox[{"{", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"\"\<CoordinateSystem\>\"", "\[Rule]", "\"\<Cartesian\>\""}], 
      ",", "\[IndentingNewLine]", 
      RowBox[{"\"\<Hold\>\"", "\[Rule]", "False"}]}], "\[IndentingNewLine]", 
     "}"}]}], ";"}], "\n"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"ComplexFit", "[", "\[IndentingNewLine]", 
     RowBox[{
     "data_", ",", "model_", ",", "pars_", ",", "vars_", ",", 
      "\[IndentingNewLine]", 
      RowBox[{"opts", ":", 
       RowBox[{"OptionsPattern", "[", 
        RowBox[{"{", 
         RowBox[{"ComplexFit", ",", "TransformedFit", ",", 
          RowBox[{"Sequence", "@@", "$FitFunctions"}]}], "}"}], "]"}]}]}], 
     "\[IndentingNewLine]", "]"}], ":=", "\[IndentingNewLine]", 
    RowBox[{"TransformedFit", "[", "\[IndentingNewLine]", 
     RowBox[{
     "data", ",", "model", ",", "pars", ",", "vars", ",", 
      "\[IndentingNewLine]", 
      RowBox[{"coordinateSystemRules", "@", 
       RowBox[{"OptionValue", "[", "\"\<CoordinateSystem\>\"", "]"}]}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"FilterRules", "[", 
       RowBox[{
        RowBox[{"{", "opts", "}"}], ",", 
        RowBox[{"Except", "[", 
         RowBox[{
         "\"\<CoordinateSystem\>\"", "|", "\"\<Transformation\>\"", "|", 
          "\"\<ParameterTransformation\>\""}], "]"}]}], "]"}]}], 
     "\[IndentingNewLine]", "]"}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"Protect", "[", "ComplexFit", "]"}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"End", "[", "]"}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"EndPackage", "[", "]"}], ";"}]}], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.556126336953125*^9, 3.5561263518125*^9}, {
   3.55612638521875*^9, 3.556126391421875*^9}, {3.5561264223125*^9, 
   3.556126434453125*^9}, {3.55612647190625*^9, 3.5561264871875*^9}, {
   3.556126534703125*^9, 3.556126588875*^9}, {3.556126621953125*^9, 
   3.556126632765625*^9}, {3.556126871234375*^9, 3.556126929140625*^9}, {
   3.5561270039375*^9, 3.55612708478125*^9}, {3.556127249203125*^9, 
   3.5561272519375*^9}, {3.556127328890625*^9, 3.55612733078125*^9}, {
   3.55612819965625*^9, 3.556128201859375*^9}, {3.556128604453125*^9, 
   3.556128629390625*^9}, {3.556128679046875*^9, 3.556128684234375*^9}, {
   3.5561287718125*^9, 3.556128810125*^9}, {3.55612895678125*^9, 
   3.556128963*^9}, 3.556129088953125*^9, {3.556129402640625*^9, 
   3.556129404890625*^9}, {3.55612946271875*^9, 3.556129464765625*^9}, {
   3.55612951584375*^9, 3.5561295351875*^9}, {3.556133279953125*^9, 
   3.556133294171875*^9}, 3.5561369235*^9, {3.55613726471875*^9, 
   3.556137268890625*^9}, {3.55613732796875*^9, 3.556137387046875*^9}, {
   3.55613750959375*^9, 3.55613752984375*^9}, {3.5561378060625*^9, 
   3.556137856046875*^9}, {3.556138750453125*^9, 3.556138855*^9}, {
   3.5561389164375*^9, 3.55613892396875*^9}, {3.556140176859375*^9, 
   3.5561401771875*^9}, {3.55614029553125*^9, 3.556140295828125*^9}, {
   3.556140893421875*^9, 3.556140893640625*^9}, 3.556141252609375*^9, {
   3.5563034829375*^9, 3.5563035160625*^9}, {3.55631361434375*^9, 
   3.556313618203125*^9}, 3.556313682203125*^9, {3.556387353328125*^9, 
   3.55638735434375*^9}, {3.556387415421875*^9, 3.556387415953125*^9}, {
   3.55638760009375*^9, 3.556387671984375*^9}, {3.5563880699375*^9, 
   3.556388114921875*^9}, {3.556398257375*^9, 3.556398305140625*^9}, {
   3.556398450515625*^9, 3.556398462359375*^9}, {3.556398538125*^9, 
   3.556398555765625*^9}, {3.556398591234375*^9, 3.556398602296875*^9}, {
   3.556398639734375*^9, 3.556398669296875*^9}, {3.55639882003125*^9, 
   3.5563988348125*^9}, {3.556399005125*^9, 3.556399010578125*^9}, {
   3.5563991175*^9, 3.556399122734375*^9}, {3.556399623765625*^9, 
   3.556399656265625*^9}, 3.556399700375*^9, {3.55640163478125*^9, 
   3.55640163528125*^9}, {3.556401784203125*^9, 3.55640178465625*^9}, {
   3.55657495746875*^9, 3.556574965046875*^9}, {3.556575004046875*^9, 
   3.5565750045625*^9}, {3.556575158546875*^9, 3.55657520190625*^9}, {
   3.55657523521875*^9, 3.556575244859375*^9}, {3.556575742421875*^9, 
   3.5565757853125*^9}, {3.556576229921875*^9, 3.556576254359375*^9}, {
   3.55657678371875*^9, 3.556576786171875*^9}, {3.556577480875*^9, 
   3.556577481296875*^9}, {3.5565777339375*^9, 3.55657775078125*^9}, {
   3.556577934671875*^9, 3.55657797896875*^9}, {3.556701655515625*^9, 
   3.55670167321875*^9}, {3.556702451828125*^9, 3.5567024816875*^9}, {
   3.556702512765625*^9, 3.5567025586875*^9}, {3.556702590328125*^9, 
   3.55670261359375*^9}, {3.5567514583125*^9, 3.55675147846875*^9}, {
   3.556751514390625*^9, 3.556751518015625*^9}, {3.556751605734375*^9, 
   3.556751654140625*^9}, {3.55675168909375*^9, 3.5567517309375*^9}, {
   3.556751801578125*^9, 3.5567518380625*^9}, {3.556751881296875*^9, 
   3.556751937734375*^9}, {3.556751976375*^9, 3.55675197915625*^9}, {
   3.556752117375*^9, 3.556752120171875*^9}, {3.556752182*^9, 
   3.55675219709375*^9}, {3.556806619375*^9, 3.556806620296875*^9}, {
   3.571704377109375*^9, 3.571704388953125*^9}, {3.579196342765625*^9, 
   3.5791963436875*^9}, {3.579196386703125*^9, 3.579196397265625*^9}, {
   3.5791964284375*^9, 3.579196557171875*^9}, {3.579196610828125*^9, 
   3.57919661190625*^9}, {3.57920580446875*^9, 3.579205814421875*^9}, 
   3.58214432984375*^9, {3.582144587375*^9, 3.582144627609375*^9}, 
   3.5821449859375*^9, {3.582145024296875*^9, 3.582145062390625*^9}, 
   3.58214521378125*^9, {3.582145289328125*^9, 3.58214529078125*^9}, {
   3.582146037109375*^9, 3.582146037890625*^9}, {3.582146895984375*^9, 
   3.582146898515625*^9}, 3.58214698928125*^9, {3.582147053625*^9, 
   3.582147059796875*^9}, {3.582147119421875*^9, 3.582147159796875*^9}, 
   3.582147228984375*^9, {3.58214777253125*^9, 3.58214777878125*^9}, {
   3.58214781178125*^9, 3.582147812421875*^9}, 3.582147993265625*^9, {
   3.582148352171875*^9, 3.58214836021875*^9}, {3.58214842903125*^9, 
   3.582148430171875*^9}, 3.582148713859375*^9, {3.582148841578125*^9, 
   3.582148842296875*^9}, {3.582151363046875*^9, 3.5821513640625*^9}, {
   3.58215141940625*^9, 3.582151459046875*^9}, 3.582159614203125*^9, {
   3.58215974165625*^9, 3.582159750078125*^9}, {3.582160111890625*^9, 
   3.582160118796875*^9}, {3.597615087734375*^9, 3.5976150975*^9}, 
   3.59761514109375*^9, {3.597615180765625*^9, 3.597615186875*^9}, {
   3.597615223703125*^9, 3.5976152243125*^9}, {3.59761529415625*^9, 
   3.597615408640625*^9}, {3.597615443578125*^9, 3.5976155185625*^9}, 
   3.5976155784375*^9, {3.597615914609375*^9, 3.597616003703125*^9}, 
   3.597617127234375*^9, {3.597617241140625*^9, 3.597617245765625*^9}, {
   3.5977076814008064`*^9, 3.5977076826664314`*^9}, {3.5977077408226814`*^9, 
   3.5977077440570564`*^9}},ExpressionUUID->"259456e8-d369-4206-ac46-\
891ef35bf721"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"2a881bf7-361e-4e5b-b511-e5cf2a8cdceb"],

Cell[CellGroupData[{

Cell["Data Import +++ requires user input +++", "Section",
 CellChangeTimes->{{3.792503789244561*^9, 3.7925038045594373`*^9}, {
  3.803296766994279*^9, 
  3.803296785264324*^9}},ExpressionUUID->"36e45152-e323-40ac-90fc-\
f53c36c5672b"],

Cell[TextData[{
 StyleBox["\[OpenCurlyDoubleQuote]work_book\[CloseCurlyDoubleQuote]", "Code"],
 " is the name of the workbook, i.e., the scenario, used for the fitting \
process;",
 StyleBox[" Range[#,#]", "Code"],
 " defines clean-shares to be included in the fitting process"
}], "Text",
 CellChangeTimes->{{3.8032969318467083`*^9, 3.803297081902291*^9}, {
  3.8032971382075114`*^9, 
  3.803297205459358*^9}},ExpressionUUID->"49471708-c688-40d9-85c1-\
872f980599be"],

Cell[BoxData[
 RowBox[{
  RowBox[{"importeddata", "=", 
   RowBox[{"Import", "[", 
    RowBox[{"\"\<C:\\\\Users\\\\...\\\\data-input-file.xlsx\>\"", ",", 
     RowBox[{"{", 
      RowBox[{"\"\<Data\>\"", ",", "\"\<work_book\>\"", ",", 
       RowBox[{"Range", "[", 
        RowBox[{"65", ",", "109"}], "]"}], ",", 
       RowBox[{"{", 
        RowBox[{"143", ",", "142", ",", "140"}], "}"}]}], "}"}]}], "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.7913955853782463`*^9, 3.7913956097836423`*^9}, {
   3.7913958914557533`*^9, 3.7913958965750456`*^9}, {3.7913960059112997`*^9, 
   3.791396018436016*^9}, {3.7913962059307404`*^9, 3.7913962122190995`*^9}, {
   3.7913963056634445`*^9, 3.791396323684475*^9}, {3.7913963986127605`*^9, 
   3.79139640506813*^9}, {3.7913964780903063`*^9, 3.7913965094731016`*^9}, {
   3.791396689718411*^9, 3.7913966969248233`*^9}, {3.791396803290907*^9, 
   3.7913968345276937`*^9}, {3.791396876822113*^9, 3.7913969186995077`*^9}, {
   3.791397210078174*^9, 3.7913972478053317`*^9}, {3.7913973648560266`*^9, 
   3.791397371998435*^9}, {3.791397416157961*^9, 3.7913974163269706`*^9}, {
   3.791397514466584*^9, 3.7913975202889166`*^9}, {3.791397779075719*^9, 
   3.791397792856507*^9}, {3.79139788277065*^9, 3.791397909579183*^9}, {
   3.7913992351730027`*^9, 3.7913992394542475`*^9}, {3.791399273101172*^9, 
   3.791399298786641*^9}, 3.791399369544688*^9, {3.7914000886278176`*^9, 
   3.791400091233967*^9}, {3.7914001233158016`*^9, 3.7914001236338196`*^9}, 
   3.7914001641941395`*^9, 3.791400299580883*^9, {3.791400367637776*^9, 
   3.791400383316673*^9}, {3.7927571035949087`*^9, 3.79275711701725*^9}, 
   3.793120379977236*^9, {3.7931204440449*^9, 3.7931204475861025`*^9}, {
   3.7931205349320984`*^9, 3.793120547865838*^9}, {3.7939840547402077`*^9, 
   3.793984061960621*^9}, {3.793984120675979*^9, 3.793984131196581*^9}, 
   3.796027455722553*^9, {3.796544683127831*^9, 3.7965447007138367`*^9}, {
   3.7965447399740825`*^9, 3.796544748740584*^9}, {3.796583562553772*^9, 
   3.796583589319303*^9}, {3.796583982367784*^9, 3.7965839827408056`*^9}, 
   3.797340957301244*^9, 3.797340999824676*^9, {3.797437319425536*^9, 
   3.7974373445329723`*^9}, {3.7974376539096675`*^9, 3.797437654284689*^9}, {
   3.7974384594467416`*^9, 3.797438463102951*^9}, {3.7995117440861807`*^9, 
   3.7995117451592417`*^9}, {3.7995118693093433`*^9, 
   3.7995118701623917`*^9}, {3.7995129222675686`*^9, 
   3.7995129259877815`*^9}, {3.7995130051283083`*^9, 3.799513006137366*^9}, {
   3.7995296442740126`*^9, 3.7995296451310616`*^9}, {3.800294861446641*^9, 
   3.800294862600707*^9}, {3.803297101547415*^9, 3.803297109180851*^9}, {
   3.803299279440983*^9, 3.803299287936469*^9}, {3.803299337749318*^9, 
   3.803299350336038*^9}, 3.803300090764388*^9, {3.803312257238305*^9, 
   3.8033122607935085`*^9}, {3.803321227559082*^9, 
   3.8033212536211185`*^9}},ExpressionUUID->"6a1e464b-cc9f-42e8-b115-\
53a99b8cc120"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"a9773362-a590-47b8-82e7-42ca58bc953e"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"dirty", "=", 
   RowBox[{"importeddata", "[", 
    RowBox[{"[", 
     RowBox[{"All", ",", "1"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"clean", "=", 
   RowBox[{"importeddata", "[", 
    RowBox[{"[", 
     RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"production", "=", 
   RowBox[{"importeddata", "[", 
    RowBox[{"[", 
     RowBox[{"All", ",", "3"}], "]"}], "]"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.79139792666216*^9, 3.791397936960749*^9}, {
  3.79139806075683*^9, 3.7913981062414317`*^9}, {3.7913981720571957`*^9, 
  3.791398183342841*^9}, {3.791398299323475*^9, 3.791398309245043*^9}, {
  3.791399204041222*^9, 3.7913992073454113`*^9}, {3.791399256587228*^9, 
  3.791399258050311*^9}, {3.791399333194609*^9, 3.791399360536173*^9}, {
  3.7913999348940244`*^9, 3.7913999737622476`*^9}, {3.7914000751250453`*^9, 
  3.791400085536641*^9}, {3.79734346245053*^9, 3.797343467748833*^9}, {
  3.797343499734663*^9, 3.7973435120373664`*^9}, {3.7995117525756664`*^9, 
  3.79951175422276*^9}},ExpressionUUID->"66b579c3-2f4c-4c9f-b761-\
c513843d8189"],

Cell[BoxData[
 RowBox[{
  RowBox[{"data", "=", 
   RowBox[{"Transpose", "[", 
    RowBox[{"{", 
     RowBox[{"clean", ",", "dirty", ",", "production"}], "}"}], "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.791399762182146*^9, 3.791399763882243*^9}, {
   3.791400068439663*^9, 3.791400094703165*^9}, {3.791400181285117*^9, 
   3.7914001847993183`*^9}, 3.792527953707786*^9, 3.7925284074147367`*^9, {
   3.797341034108637*^9, 3.797341060977174*^9}, 3.797341114449232*^9, 
   3.797341209543671*^9, {3.7973427031330996`*^9, 3.797342704833197*^9}, 
   3.7973434432234306`*^9, 
   3.7973435155745687`*^9},ExpressionUUID->"4ad31d95-99f0-4265-a8a1-\
0c06c43aa446"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"originaldataforplot", "=", 
   RowBox[{"Transpose", "@", 
    RowBox[{"{", 
     RowBox[{"dirty", ",", "clean"}], "}"}]}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{"originaldataplot", "=", 
   RowBox[{"ListPlot", "[", 
    RowBox[{"originaldataforplot", ",", 
     RowBox[{"AspectRatio", "\[Rule]", "1"}], ",", 
     RowBox[{"AxesLabel", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{"\"\<D\>\"", ",", "\"\<C\>\""}], "}"}]}], ",", 
     RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.7904401585666847`*^9, 3.790440299473859*^9}, {
   3.790440424098859*^9, 3.7904404484488587`*^9}, {3.790440612855859*^9, 
   3.7904406507418585`*^9}, {3.7904458064690557`*^9, 3.790445809877608*^9}, {
   3.790447296337081*^9, 3.7904473021771855`*^9}, {3.7904511417003775`*^9, 
   3.790451146370951*^9}, {3.7904512565357156`*^9, 3.7904512765470824`*^9}, {
   3.790451900955495*^9, 3.7904519056057615`*^9}, {3.790452008202629*^9, 
   3.790452037977332*^9}, {3.790452630537225*^9, 3.7904526345994573`*^9}, 
   3.790453114664915*^9, 3.7904548674051666`*^9, {3.7905121270307817`*^9, 
   3.7905121298379426`*^9}, 3.7905128886823463`*^9, 3.790513974797674*^9, {
   3.7905159992890105`*^9, 3.7905160165459976`*^9}, 3.7905161177707872`*^9, {
   3.790602733141533*^9, 
   3.790602736309714*^9}},ExpressionUUID->"24bd5555-f06e-4c85-8d11-\
cf7e2ea83ef1"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"b78146b6-3b21-44c0-a790-a4dc29406b2f"]
}, Open  ]],

Cell[CellGroupData[{

Cell["Options", "Section",
 CellChangeTimes->{{3.7925038239365454`*^9, 
  3.79250383275905*^9}},ExpressionUUID->"38829f7b-b9db-4453-bc4d-\
183431fadd9e"],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"mynormfunction", "=", 
    RowBox[{"(", 
     RowBox[{
      RowBox[{"Norm", "[", 
       RowBox[{"#", ",", "2"}], "]"}], "&"}], ")"}]}], ";"}], " ", 
  RowBox[{"(*", " ", 
   RowBox[{"Do", " ", "NOT", " ", "change"}], " ", "*)"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"opsearchp", "=", "500"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"opscaling", "=", 
   RowBox[{"{", 
    RowBox[{"0.1", ",", "0.45", ",", "0.95", ",", "1", ",", "1.5"}], "}"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"opcrossprob", "=", 
   RowBox[{"{", 
    RowBox[{"0.001", ",", "0.05", ",", "0.1", ",", "0.3"}], "}"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"ops", "=", 
   RowBox[{"Tuples", "[", 
    RowBox[{"{", 
     RowBox[{"opscaling", ",", "opcrossprob"}], "}"}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{"Length", "[", "ops", "]"}]}], "Input",
 CellChangeTimes->{{3.7924914535531654`*^9, 3.792491691375165*^9}, {
   3.792491914533165*^9, 3.792491928849165*^9}, {3.7924919770221653`*^9, 
   3.792491979974165*^9}, {3.792493313638254*^9, 3.792493343554236*^9}, {
   3.7924999886607647`*^9, 3.7924999962101965`*^9}, {3.792504440202794*^9, 
   3.792504440465809*^9}, {3.792505237992425*^9, 3.792505262221811*^9}, 
   3.7925137239672613`*^9, {3.792513759800311*^9, 3.7925138104502077`*^9}, 
   3.792514056416276*^9, {3.792516043574935*^9, 3.7925160714655304`*^9}, {
   3.792672577032957*^9, 3.7926725937506285`*^9}, {3.7926771788715734`*^9, 
   3.79267720153887*^9}, {3.7931216288996696`*^9, 3.793121640500334*^9}, {
   3.7939840979116774`*^9, 3.793984100316815*^9}, {3.7965448628438473`*^9, 
   3.7965448963933*^9}, {3.7965452971813574`*^9, 3.7965452986054387`*^9}, {
   3.796545564833666*^9, 3.796545566330752*^9}, {3.796545599024622*^9, 
   3.7965456059970207`*^9}, {3.7974083850433593`*^9, 3.797408390464669*^9}, 
   3.8032972665428514`*^9, {3.803298265543991*^9, 3.8032983157388625`*^9}, {
   3.803299184834572*^9, 3.803299200454465*^9}, {3.803299714505867*^9, 
   3.803299748556815*^9}, {3.8033212911701713`*^9, 
   3.8033213083971953`*^9}},ExpressionUUID->"3153aff7-87fc-47ca-9f63-\
f2758c227b88"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"7871f16d-4d7a-492b-8bbd-4d040eab80ec"]
}, Open  ]],

Cell[CellGroupData[{

Cell["CES", "Section",
 CellChangeTimes->{{3.792503841639558*^9, 
  3.7925038551983337`*^9}},ExpressionUUID->"62393d1e-6487-4044-9f24-\
3927af8fdb15"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"cesfitlist", "=", 
   RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"cescount", "=", "0"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"cesplots", "=", 
   RowBox[{"{", "}"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.7924917426311655`*^9, 3.792491747906165*^9}, {
   3.792493554446786*^9, 3.7924935591482563`*^9}, {3.7924938392012587`*^9, 
   3.7924938403203707`*^9}, 3.792494076490985*^9, {3.792494336318965*^9, 
   3.792494348943228*^9}, {3.792495036807007*^9, 3.7924950382951555`*^9}, {
   3.7924957703089533`*^9, 3.7924957728209534`*^9}, {3.792504236571147*^9, 
   3.792504258746415*^9}, {3.7925145308394117`*^9, 
   3.792514531561453*^9}},ExpressionUUID->"8659ca9f-9167-4e1c-9fe7-\
a3fb993ddfa4"],

Cell[BoxData[
 RowBox[{"Dynamic", "[", 
  RowBox[{"cescount", ",", 
   RowBox[{"UpdateInterval", "\[Rule]", "1"}]}], "]"}]], "Input",
 CellChangeTimes->{{3.7925041877163525`*^9, 
  3.792504202763213*^9}},ExpressionUUID->"33780faa-97e8-41a5-af15-\
7665dd6833eb"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Do", "[", "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"loopscaling", "=", 
      RowBox[{
       RowBox[{"ops", "[", 
        RowBox[{"[", 
         RowBox[{"cescount", "+", "1"}], "]"}], "]"}], "[", 
       RowBox[{"[", "1", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"loopopcrossprob", "=", 
      RowBox[{
       RowBox[{"ops", "[", 
        RowBox[{"[", 
         RowBox[{"cescount", "+", "1"}], "]"}], "]"}], "[", 
       RowBox[{"[", "2", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
     "\[IndentingNewLine]", 
     RowBox[{"cesfit", "=", 
      RowBox[{"ComplexFit", "[", 
       RowBox[{"data", ",", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"model", "=", 
           RowBox[{"cestfp", "*", 
            RowBox[{"(", 
             RowBox[{
              RowBox[{"(", 
               RowBox[{
                RowBox[{"\[Alpha]", " ", 
                 RowBox[{"x", "^", "\[Rho]"}]}], " ", "+", " ", 
                RowBox[{
                 RowBox[{"(", 
                  RowBox[{"1", "-", "\[Alpha]"}], ")"}], " ", 
                 RowBox[{"y", "^", "\[Rho]"}]}]}], ")"}], "^", 
              RowBox[{"(", 
               RowBox[{"1", "/", "\[Rho]"}], ")"}]}], ")"}]}]}], ",", 
          RowBox[{
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "cestfp"}], "]"}], ">", "0"}], ",", 
          RowBox[{"0", "<", 
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "\[Alpha]"}], "]"}]}], ",", 
          RowBox[{
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "\[Alpha]"}], "]"}], "<", "1"}], ",", 
          RowBox[{
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "\[Rho]"}], "]"}], "<", "1"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"\[Alpha]", ",", "\[Rho]", ",", "cestfp"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"x", ",", "y"}], "}"}], ",", 
        RowBox[{"NormFunction", "\[Rule]", "mynormfunction"}], ",", 
        RowBox[{"\"\<CoordinateSystem\>\"", "\[Rule]", "\"\<Real\>\""}], ",", 
        RowBox[{"Method", "\[Rule]", 
         RowBox[{"{", 
          RowBox[{"NMinimize", ",", 
           RowBox[{"Method", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{"\"\<DifferentialEvolution\>\"", ",", 
              RowBox[{"\"\<SearchPoints\>\"", "\[Rule]", "opsearchp"}], ",", 
              RowBox[{"\"\<ScalingFactor\>\"", "\[Rule]", "loopscaling"}], 
              ",", 
              RowBox[{
              "\"\<CrossProbability\>\"", "\[Rule]", "loopopcrossprob"}], ",", 
              RowBox[{"\"\<PostProcess\>\"", "\[Rule]", 
               RowBox[{"{", 
                RowBox[{"FindMinimum", ",", 
                 RowBox[{"Method", "\[Rule]", "\"\<QuasiNewton\>\""}]}], 
                "}"}]}]}], "}"}]}]}], "}"}]}]}], "]"}]}], ";", 
     "\[IndentingNewLine]", "\[IndentingNewLine]", 
     RowBox[{"cespredelec", "=", 
      RowBox[{
       RowBox[{"Evaluate", "[", 
        RowBox[{
         RowBox[{"cestfp", "*", 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"(", 
             RowBox[{
              RowBox[{"\[Alpha]", " ", 
               RowBox[{"x", "^", "\[Rho]"}]}], " ", "+", " ", 
              RowBox[{
               RowBox[{"(", 
                RowBox[{"1", "-", "\[Alpha]"}], ")"}], " ", 
               RowBox[{"y", "^", "\[Rho]"}]}]}], ")"}], "^", 
            RowBox[{"(", 
             RowBox[{"1", "/", "\[Rho]"}], ")"}]}], ")"}]}], "/.", "cesfit"}],
         "]"}], "/.", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"x", "\[Rule]", "clean"}], ",", 
         RowBox[{"y", "\[Rule]", "dirty"}]}], "}"}]}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"cespredelecerror", "=", 
      RowBox[{"cespredelec", "-", "production"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"cespredelecmeansquarederror", "=", 
      RowBox[{
       RowBox[{"Total", "[", 
        RowBox[{"cespredelecerror", "^", "2"}], "]"}], "/", 
       RowBox[{"Length", "[", "clean", "]"}]}]}], ";", "\[IndentingNewLine]", 
     "\[IndentingNewLine]", 
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"NonNegative", "[", "cespredelecmeansquarederror", "]"}], ",", 
       "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"cesfittedplot", "=", 
         RowBox[{"Plot", "[", 
          RowBox[{
           RowBox[{
            RowBox[{"(", 
             RowBox[{
              RowBox[{"(", 
               RowBox[{
                RowBox[{"(", 
                 RowBox[{
                  RowBox[{
                   RowBox[{"(", 
                    RowBox[{
                    RowBox[{"production", "[", 
                    RowBox[{"[", "1", "]"}], "]"}], "/", "cestfp"}], ")"}], 
                   "^", "\[Rho]"}], " ", "-", " ", 
                  RowBox[{
                   RowBox[{"(", 
                    RowBox[{"1", "-", "\[Alpha]"}], ")"}], " ", 
                   RowBox[{"x", "^", "\[Rho]"}]}]}], ")"}], "/", "\[Alpha]"}],
                ")"}], "^", 
              RowBox[{"(", 
               RowBox[{"1", "/", "\[Rho]"}], ")"}]}], ")"}], "/.", "cesfit"}],
            ",", 
           RowBox[{"{", 
            RowBox[{"x", ",", 
             RowBox[{"Min", "[", "dirty", "]"}], ",", 
             RowBox[{"Max", "[", "dirty", "]"}]}], "}"}], ",", 
           RowBox[{"PlotStyle", "\[Rule]", "Green"}]}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"cescomparisonplot", "=", 
         RowBox[{"Show", "[", 
          RowBox[{"originaldataplot", ",", "cesfittedplot", ",", 
           RowBox[{"Prolog", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{"Inset", "[", 
              RowBox[{
               RowBox[{"Framed", "[", 
                RowBox[{
                 RowBox[{"Style", "[", 
                  RowBox[{"\"\<CES\>\"", ",", "14"}], "]"}], ",", 
                 RowBox[{"RoundingRadius", "\[Rule]", "5"}], ",", 
                 RowBox[{"Background", "\[Rule]", "White"}]}], "]"}], ",", 
               RowBox[{"Scaled", "[", 
                RowBox[{"{", 
                 RowBox[{
                  RowBox[{"1", "/", "2"}], ",", 
                  RowBox[{"1", "-", 
                   RowBox[{"1", "/", "8"}]}]}], "}"}], "]"}]}], "]"}], 
             "}"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"AppendTo", "[", 
         RowBox[{"cesfitlist", ",", 
          RowBox[{"{", 
           RowBox[{"cesfit", ",", "cespredelecmeansquarederror"}], "}"}]}], 
         "]"}], ";", "\[IndentingNewLine]", 
        RowBox[{"AppendTo", "[", 
         RowBox[{"cesplots", ",", "cescomparisonplot"}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"Print", "[", 
         RowBox[{
          RowBox[{"ToString", "[", 
           RowBox[{"cescount", "+", "1"}], "]"}], ",", "\"\< - Yeahhh! \>\"", 
          " ", ",", 
          RowBox[{"cesfitlist", "[", 
           RowBox[{"[", 
            RowBox[{"cescount", "+", "1"}], "]"}], "]"}]}], "]"}], ";"}], 
       "\[IndentingNewLine]", ",", "\[IndentingNewLine]", 
       "\[IndentingNewLine]", 
       RowBox[{"Print", "[", 
        RowBox[{
         RowBox[{"ToString", "[", 
          RowBox[{"cescount", "+", "1"}], "]"}], ",", 
         "\"\< - Oh nooooo!\>\""}], "]"}]}], "\[IndentingNewLine]", "]"}], 
     ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
     RowBox[{"cescount", "=", 
      RowBox[{"cescount", "+", "1"}]}], ";"}], "\[IndentingNewLine]", 
    "\[IndentingNewLine]", ",", " ", 
    RowBox[{"Length", "[", "ops", "]"}]}], "\[IndentingNewLine]", "]"}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.790600450327963*^9, 3.7906004503289633`*^9}, {
   3.790600531411601*^9, 3.790600583218564*^9}, {3.790600669181481*^9, 
   3.7906006710835896`*^9}, {3.7906007162621737`*^9, 
   3.7906007608517237`*^9}, {3.790600792365526*^9, 3.7906008127696934`*^9}, {
   3.7906009564099092`*^9, 3.7906009577059836`*^9}, {3.7906011365762143`*^9, 
   3.7906011646428194`*^9}, {3.7906013471562586`*^9, 3.790601358297896*^9}, {
   3.7906013939239335`*^9, 3.790601440574602*^9}, 3.7906018089466715`*^9, 
   3.790601844516706*^9, {3.7906019614883966`*^9, 3.790601978595375*^9}, 
   3.790602649163729*^9, {3.7906035349093914`*^9, 3.790603559788814*^9}, {
   3.790603643381595*^9, 3.790603788893918*^9}, {3.790604382173852*^9, 
   3.7906043836679373`*^9}, {3.7906099167924137`*^9, 3.790609963316075*^9}, {
   3.7906113123932376`*^9, 3.7906113296732264`*^9}, {3.7906612096810637`*^9, 
   3.790661222191779*^9}, 3.790661363785878*^9, {3.7906615199318085`*^9, 
   3.7906615202778287`*^9}, {3.792491833344165*^9, 3.792491839952165*^9}, {
   3.7924918840531654`*^9, 3.792492072636165*^9}, {3.792492162255165*^9, 
   3.792492175398165*^9}, {3.792492300839165*^9, 3.792492314814165*^9}, {
   3.792492688945165*^9, 3.792492699576165*^9}, {3.7924928224571652`*^9, 
   3.7924929482201653`*^9}, {3.792492996130165*^9, 3.7924930028971653`*^9}, 
   3.7924934612854705`*^9, {3.7924935647538166`*^9, 3.7924935931476555`*^9}, {
   3.7924938579031286`*^9, 3.7924938628556232`*^9}, {3.7924945577651076`*^9, 
   3.7924946295462847`*^9}, {3.79249471050238*^9, 3.792494763097639*^9}, {
   3.7924950309914255`*^9, 3.792495032045531*^9}, {3.792495786331953*^9, 
   3.792495808480953*^9}, {3.7924986568679485`*^9, 3.792498683885948*^9}, {
   3.7924992540091224`*^9, 3.79249925458318*^9}, {3.7924993219009113`*^9, 
   3.7924993348282037`*^9}, {3.792501426472003*^9, 3.7925014284721174`*^9}, {
   3.792513507241865*^9, 3.79251353548048*^9}, {3.792513594849876*^9, 
   3.7925136432626452`*^9}, {3.7925144427633743`*^9, 3.792514451712886*^9}, {
   3.792514520182802*^9, 3.792514527546223*^9}, {3.7925156856434627`*^9, 
   3.79251570255443*^9}, {3.7925163138273926`*^9, 3.7925163506975017`*^9}, {
   3.792673245277585*^9, 3.7926732514249363`*^9}, {3.7926733712737913`*^9, 
   3.792673427798024*^9}, {3.7926736220901375`*^9, 3.792673647077566*^9}, {
   3.7926741619660163`*^9, 3.792674185399357*^9}, 3.7926743036551204`*^9, {
   3.7926750937973137`*^9, 3.792675095847431*^9}, {3.793984188029832*^9, 
   3.7939842061318674`*^9}, 3.7940451830403767`*^9, {3.7965458234414577`*^9, 
   3.7965458297628193`*^9}, {3.7965458649768333`*^9, 
   3.7965459247692533`*^9}, {3.7965524390574884`*^9, 3.796552448735075*^9}, {
   3.797342757529211*^9, 3.7973427726250744`*^9}, {3.7973428295513306`*^9, 
   3.7973428483244042`*^9}, {3.797342885281518*^9, 3.797342940196659*^9}, {
   3.7973430161180015`*^9, 3.797343064660778*^9}, {3.797343739356368*^9, 
   3.7973437423655405`*^9}, {3.7973437790226374`*^9, 
   3.7973438245072384`*^9}, {3.7973438855757313`*^9, 3.797343898934496*^9}, 
   3.7973442236570687`*^9, {3.7973445434963627`*^9, 3.7973445445494227`*^9}, {
   3.7973448165939827`*^9, 3.797344824519436*^9}, {3.7973448947254515`*^9, 
   3.7973449178997774`*^9}, {3.7973449883288054`*^9, 3.797344995297204*^9}, {
   3.797345097005021*^9, 3.7973450976170564`*^9}, {3.7973452678757944`*^9, 
   3.7973452690848637`*^9}, {3.7973453598730564`*^9, 
   3.7973453702986526`*^9}, {3.7973454608428316`*^9, 
   3.7973454870513306`*^9}, {3.79734629844974*^9, 3.7973463058571634`*^9}, {
   3.797346812067117*^9, 3.7973468403947372`*^9}, {3.7973470049281483`*^9, 
   3.7973470156817636`*^9}, {3.797347398882681*^9, 3.797347400557777*^9}, {
   3.7973477972674675`*^9, 3.7973478188927045`*^9}, {3.797348102887948*^9, 
   3.7973481081912518`*^9}, {3.7973482518194666`*^9, 3.797348252124484*^9}, {
   3.8032974375816345`*^9, 3.803297443562977*^9}, {3.803297547789938*^9, 
   3.803297559917632*^9}, 3.8032976379820967`*^9, {3.8032979368801928`*^9, 
   3.8032979375692325`*^9}, {3.803297992497374*^9, 3.803297993170412*^9}, 
   3.8032983784184475`*^9, {3.8032985024625425`*^9, 3.803298510136981*^9}, {
   3.803298656468351*^9, 3.8032986594145193`*^9}, {3.8032986905523005`*^9, 
   3.8032986925584154`*^9}, {3.8033002332965403`*^9, 
   3.8033002365647273`*^9}, {3.8033003118180313`*^9, 3.803300314175166*^9}, {
   3.803300560154236*^9, 3.8033005605542583`*^9}, {3.8033015415893707`*^9, 
   3.803301541598371*^9}, {3.8033015743852463`*^9, 3.8033015743902464`*^9}, {
   3.803301655116864*^9, 
   3.803301655123864*^9}},ExpressionUUID->"14262c8f-b500-45d8-85e2-\
8ee42f8b1799"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"5edae6f4-890d-4147-a8dc-7c5fbbf41869"],

Cell[BoxData[
 RowBox[{"Column", "[", "cesplots", "]"}]], "Input",
 CellChangeTimes->{{3.7924991698049483`*^9, 3.7924991760549483`*^9}, {
  3.7924998129977174`*^9, 3.7924998172209587`*^9}, {3.792499882384686*^9, 
  3.7924998827027044`*^9}},ExpressionUUID->"93e18996-f900-417c-a0f5-\
7aab40656f94"],

Cell[BoxData["cesfitlist"], "Input",ExpressionUUID->"0f3c3344-f123-48e7-8676-c264b4361b91"],

Cell[BoxData[
 RowBox[{"ceslowestelecerror", "=", 
  RowBox[{
   RowBox[{
    RowBox[{"Position", "[", 
     RowBox[{
      RowBox[{"cesfitlist", "[", 
       RowBox[{"[", 
        RowBox[{"All", ",", "2"}], "]"}], "]"}], ",", 
      RowBox[{"Min", "[", 
       RowBox[{"cesfitlist", "[", 
        RowBox[{"[", 
         RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], "]"}], "[", 
    RowBox[{"[", "1", "]"}], "]"}], "[", 
   RowBox[{"[", "1", "]"}], "]"}]}]], "Input",
 CellChangeTimes->{{3.792502220435415*^9, 3.7925022585645957`*^9}, {
  3.797347446000376*^9, 3.797347487097727*^9}, {3.797347725250348*^9, 
  3.797347762414474*^9}, {3.8032988793100967`*^9, 3.8032988800841413`*^9}, {
  3.8032989217935266`*^9, 
  3.8032989245466843`*^9}},ExpressionUUID->"51b4775e-5f68-428c-8707-\
fe6afcd17dc3"],

Cell[BoxData[
 RowBox[{"cesfit", "=", 
  RowBox[{"Flatten", "[", 
   RowBox[{
    RowBox[{"cesfitlist", "[", 
     RowBox[{"[", 
      RowBox[{"All", ",", "1"}], "]"}], "]"}], "[", 
    RowBox[{"[", "ceslowestelecerror", "]"}], "]"}], "]"}]}]], "Input",
 CellChangeTimes->{{3.7925006285833664`*^9, 3.792500725790926*^9}, {
   3.792500806442539*^9, 3.792500811733842*^9}, {3.7925011093468647`*^9, 
   3.7925011108489504`*^9}, {3.792502196415041*^9, 3.7925021986581693`*^9}, 
   3.792674593944724*^9, {3.7974069168363824`*^9, 3.797406925471876*^9}, {
   3.8033003205955334`*^9, 
   3.803300320938553*^9}},ExpressionUUID->"ff337507-7852-45dd-b24a-\
1e2b2abdb970"],

Cell[BoxData[
 RowBox[{
  RowBox[{"cesfittedplot", "=", 
   RowBox[{"Plot", "[", 
    RowBox[{
     RowBox[{
      RowBox[{"(", 
       RowBox[{
        RowBox[{"(", 
         RowBox[{
          RowBox[{"(", 
           RowBox[{
            RowBox[{
             RowBox[{"(", 
              RowBox[{
               RowBox[{"production", "[", 
                RowBox[{"[", "1", "]"}], "]"}], "/", "cestfp"}], ")"}], "^", 
             "\[Rho]"}], " ", "-", " ", 
            RowBox[{
             RowBox[{"(", 
              RowBox[{"1", "-", "\[Alpha]"}], ")"}], " ", 
             RowBox[{"x", "^", "\[Rho]"}]}]}], ")"}], "/", "\[Alpha]"}], 
         ")"}], "^", 
        RowBox[{"(", 
         RowBox[{"1", "/", "\[Rho]"}], ")"}]}], ")"}], "/.", "cesfit"}], ",", 
     RowBox[{"{", 
      RowBox[{"x", ",", 
       RowBox[{"Min", "[", "dirty", "]"}], ",", 
       RowBox[{"Max", "[", "dirty", "]"}]}], "}"}], ",", 
     RowBox[{"PlotStyle", "\[Rule]", "Green"}]}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.7906093589355063`*^9, 3.7906093682890415`*^9}, {
   3.7906093998068438`*^9, 3.7906094042961006`*^9}, {3.7906095697165623`*^9, 
   3.7906095865315237`*^9}, 3.7906097429124684`*^9, 3.7906099901106076`*^9, {
   3.79066123374444*^9, 3.790661248819302*^9}, {3.7906642668029213`*^9, 
   3.7906642826558275`*^9}, {3.790664324883243*^9, 3.7906643257112904`*^9}, 
   3.7906656511221*^9, 3.790666054896194*^9, 3.790666088335107*^9, {
   3.790666407785378*^9, 3.790666434638914*^9}, 3.7925032749119415`*^9, 
   3.7925036270668135`*^9},ExpressionUUID->"d52d0398-fa0e-47ee-a474-\
5644a25d437c"],

Cell[BoxData[
 RowBox[{"cescomparisonplot", "=", 
  RowBox[{"Show", "[", 
   RowBox[{"originaldataplot", ",", "cesfittedplot", ",", 
    RowBox[{"Prolog", "\[Rule]", 
     RowBox[{"{", 
      RowBox[{"Inset", "[", 
       RowBox[{
        RowBox[{"Framed", "[", 
         RowBox[{
          RowBox[{"Style", "[", 
           RowBox[{"\"\<CES\>\"", ",", "14"}], "]"}], ",", 
          RowBox[{"RoundingRadius", "\[Rule]", "5"}], ",", 
          RowBox[{"Background", "\[Rule]", "White"}]}], "]"}], ",", 
        RowBox[{"Scaled", "[", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"1", "/", "2"}], ",", 
           RowBox[{"1", "-", 
            RowBox[{"1", "/", "8"}]}]}], "}"}], "]"}]}], "]"}], "}"}]}]}], 
   "]"}]}]], "Input",
 CellChangeTimes->{{3.790604439628138*^9, 3.79060445085078*^9}, {
   3.7906103327912073`*^9, 3.7906103341692867`*^9}, 3.790610783286975*^9, {
   3.7906614877289667`*^9, 3.7906614896600776`*^9}, {3.7906626488733807`*^9, 
   3.7906626574558716`*^9}, {3.7906643389670486`*^9, 3.7906643392610655`*^9}, 
   3.7906660501909246`*^9, 3.7906660905012302`*^9, 3.792503629867094*^9, 
   3.8033015744092474`*^9},ExpressionUUID->"987b78b1-3a04-4103-aa89-\
66787d2db23c"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"b83e1809-79c9-415f-9cd2-2d5968a4bab8"]
}, Open  ]],

Cell[CellGroupData[{

Cell["VES", "Section",
 CellChangeTimes->{{3.7925039386641073`*^9, 
  3.7925039553240604`*^9}},ExpressionUUID->"0165713a-df90-41ab-b0bd-\
72bbdfc4ecdc"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"vesfitlist", "=", 
   RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"vescount", "=", "0"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"vesplots", "=", 
   RowBox[{"{", "}"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.792514542594084*^9, 
  3.792514542944104*^9}},ExpressionUUID->"832df3c5-0359-4715-a806-\
3ed2db8601af"],

Cell[BoxData[
 RowBox[{"Dynamic", "[", 
  RowBox[{"vescount", ",", 
   RowBox[{"UpdateInterval", "\[Rule]", "1"}]}], "]"}]], "Input",
 CellChangeTimes->{{3.7925042856749554`*^9, 
  3.792504286044976*^9}},ExpressionUUID->"1fff40cd-342e-4cff-ad5e-\
d4023ec82cf5"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Do", "[", "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"loopscaling", "=", 
      RowBox[{
       RowBox[{"ops", "[", 
        RowBox[{"[", 
         RowBox[{"vescount", "+", "1"}], "]"}], "]"}], "[", 
       RowBox[{"[", "1", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"loopopcrossprob", "=", 
      RowBox[{
       RowBox[{"ops", "[", 
        RowBox[{"[", 
         RowBox[{"vescount", "+", "1"}], "]"}], "]"}], "[", 
       RowBox[{"[", "2", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
     "\[IndentingNewLine]", 
     RowBox[{"vesfit", "=", 
      RowBox[{"ComplexFit", "[", 
       RowBox[{"data", ",", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"model", "=", 
           RowBox[{"x", " ", "vestfp", "*", 
            RowBox[{"(", 
             RowBox[{
              RowBox[{"(", 
               RowBox[{"y", "/", "x"}], ")"}], "^", "a"}], ")"}], 
            RowBox[{"(", 
             RowBox[{
              RowBox[{"(", 
               RowBox[{"1", "+", 
                RowBox[{"(", 
                 RowBox[{"a", " ", "b", " ", 
                  RowBox[{"(", 
                   RowBox[{"y", "/", "x"}], ")"}]}], ")"}]}], ")"}], "^", 
              RowBox[{"(", 
               RowBox[{"1", "-", "a"}], ")"}]}], ")"}]}]}], ",", 
          RowBox[{
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "vestfp"}], "]"}], ">", "0"}], ",", 
          RowBox[{"0", "<", 
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "a"}], "]"}]}], ",", 
          RowBox[{
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "a"}], "]"}], "<", "1"}], ",", 
          RowBox[{
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "b"}], "]"}], ">", 
           RowBox[{"(", 
            RowBox[{"-", "1"}], ")"}]}], ",", 
          RowBox[{
           RowBox[{
            RowBox[{"-", " ", "1"}], "/", 
            RowBox[{"Min", "[", 
             RowBox[{"clean", "/", "dirty"}], "]"}]}], "\[LessEqual]", 
           RowBox[{"TransformedParameter", "[", 
            RowBox[{"Re", ",", "b"}], "]"}]}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"a", ",", "b", ",", "vestfp"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"x", ",", "y"}], "}"}], ",", 
        RowBox[{"NormFunction", "\[Rule]", "mynormfunction"}], ",", 
        RowBox[{"\"\<CoordinateSystem\>\"", "\[Rule]", "\"\<Real\>\""}], ",", 
        RowBox[{"Method", "\[Rule]", 
         RowBox[{"{", 
          RowBox[{"NMinimize", ",", 
           RowBox[{"Method", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{"\"\<DifferentialEvolution\>\"", ",", 
              RowBox[{"\"\<SearchPoints\>\"", "\[Rule]", "opsearchp"}], ",", 
              RowBox[{"\"\<ScalingFactor\>\"", "\[Rule]", "loopscaling"}], 
              ",", 
              RowBox[{
              "\"\<CrossProbability\>\"", "\[Rule]", "loopopcrossprob"}], ",", 
              RowBox[{"\"\<PostProcess\>\"", "\[Rule]", 
               RowBox[{"{", 
                RowBox[{"FindMinimum", ",", 
                 RowBox[{"Method", "\[Rule]", "\"\<QuasiNewton\>\""}]}], 
                "}"}]}]}], "}"}]}]}], "}"}]}]}], "]"}]}], ";", 
     "\[IndentingNewLine]", "\[IndentingNewLine]", 
     RowBox[{"vespredelec", "=", 
      RowBox[{
       RowBox[{"Evaluate", "[", 
        RowBox[{
         RowBox[{"x", " ", "vestfp", "*", 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"(", 
             RowBox[{"y", "/", "x"}], ")"}], "^", "a"}], ")"}], 
          RowBox[{"(", 
           RowBox[{
            RowBox[{"(", 
             RowBox[{"1", "+", 
              RowBox[{"(", 
               RowBox[{"a", " ", "b", " ", 
                RowBox[{"(", 
                 RowBox[{"y", "/", "x"}], ")"}]}], ")"}]}], ")"}], "^", 
            RowBox[{"(", 
             RowBox[{"1", "-", "a"}], ")"}]}], ")"}]}], "/.", "vesfit"}], 
        "]"}], "/.", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"x", "\[Rule]", "clean"}], ",", 
         RowBox[{"y", "\[Rule]", "dirty"}]}], "}"}]}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"vespredelecerror", "=", 
      RowBox[{"vespredelec", "-", 
       RowBox[{"production", "[", 
        RowBox[{"[", "1", "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"vespredelecmeansquarederror", "=", 
      RowBox[{
       RowBox[{"Total", "[", 
        RowBox[{"vespredelecerror", "^", "2"}], "]"}], "/", 
       RowBox[{"Length", "[", "clean", "]"}]}]}], ";", "\[IndentingNewLine]", 
     "\[IndentingNewLine]", 
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"NonNegative", "[", "vespredelecmeansquarederror", "]"}], ",", 
       "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"vesfittedplot", "=", 
         RowBox[{"Plot", "[", 
          RowBox[{
           RowBox[{
            RowBox[{
             RowBox[{
              RowBox[{"(", 
               RowBox[{
                RowBox[{"(", 
                 RowBox[{
                  RowBox[{"production", "[", 
                   RowBox[{"[", "1", "]"}], "]"}], "/", "vestfp"}], ")"}], 
                RowBox[{"(", 
                 RowBox[{"x", "^", 
                  RowBox[{"(", 
                   RowBox[{"-", "a"}], ")"}]}], ")"}]}], ")"}], "^", 
              RowBox[{"(", 
               RowBox[{"1", "/", 
                RowBox[{"(", 
                 RowBox[{"1", "-", "a"}], ")"}]}], ")"}]}], " ", "-", " ", 
             RowBox[{"(", 
              RowBox[{"b", " ", "a", " ", "x"}], ")"}]}], "/.", "vesfit"}], 
           ",", 
           RowBox[{"{", 
            RowBox[{"x", ",", 
             RowBox[{"Min", "[", "dirty", "]"}], ",", 
             RowBox[{"Max", "[", "dirty", "]"}]}], "}"}], ",", 
           RowBox[{"PlotStyle", "\[Rule]", "Green"}]}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"vescomparisonplot", "=", 
         RowBox[{"Show", "[", 
          RowBox[{"originaldataplot", ",", "vesfittedplot", ",", 
           RowBox[{"Prolog", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{"Inset", "[", 
              RowBox[{
               RowBox[{"Framed", "[", 
                RowBox[{
                 RowBox[{"Style", "[", 
                  RowBox[{"\"\<VES\>\"", ",", "14"}], "]"}], ",", 
                 RowBox[{"RoundingRadius", "\[Rule]", "5"}], ",", 
                 RowBox[{"Background", "\[Rule]", "White"}]}], "]"}], ",", 
               RowBox[{"Scaled", "[", 
                RowBox[{"{", 
                 RowBox[{
                  RowBox[{"1", "/", "2"}], ",", 
                  RowBox[{"1", "-", 
                   RowBox[{"1", "/", "8"}]}]}], "}"}], "]"}]}], "]"}], 
             "}"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"AppendTo", "[", 
         RowBox[{"vesfitlist", ",", 
          RowBox[{"{", 
           RowBox[{"vesfit", ",", "vespredelecmeansquarederror"}], "}"}]}], 
         "]"}], ";", "\[IndentingNewLine]", 
        RowBox[{"AppendTo", "[", 
         RowBox[{"vesplots", ",", "vescomparisonplot"}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"Print", "[", 
         RowBox[{
          RowBox[{"ToString", "[", 
           RowBox[{"vescount", "+", "1"}], "]"}], ",", "\"\< - Yeahhh! \>\"", 
          " ", ",", 
          RowBox[{"vesfitlist", "[", 
           RowBox[{"[", 
            RowBox[{"vescount", "+", "1"}], "]"}], "]"}]}], "]"}], ";"}], 
       "\[IndentingNewLine]", "\[IndentingNewLine]", ",", 
       "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{"Print", "[", 
        RowBox[{
         RowBox[{"ToString", "[", 
          RowBox[{"vescount", "+", "1"}], "]"}], ",", 
         "\"\< - Oh nooooo!\>\""}], "]"}]}], "\[IndentingNewLine]", "]"}], 
     ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
     RowBox[{"vescount", "=", 
      RowBox[{"vescount", "+", "1"}]}], ";"}], "\[IndentingNewLine]", 
    "\[IndentingNewLine]", ",", " ", 
    RowBox[{"Length", "[", "ops", "]"}]}], "\[IndentingNewLine]", "]"}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.790600450327963*^9, 3.7906004503289633`*^9}, {
   3.790600531411601*^9, 3.790600583218564*^9}, {3.790600669181481*^9, 
   3.7906006710835896`*^9}, {3.7906007162621737`*^9, 
   3.7906007608517237`*^9}, {3.790600792365526*^9, 3.7906008127696934`*^9}, {
   3.7906009564099092`*^9, 3.7906009577059836`*^9}, {3.7906011365762143`*^9, 
   3.7906011646428194`*^9}, {3.7906013471562586`*^9, 3.790601358297896*^9}, {
   3.7906013939239335`*^9, 3.790601440574602*^9}, 3.7906018089466715`*^9, 
   3.790601844516706*^9, {3.7906019614883966`*^9, 3.790601978595375*^9}, 
   3.790602649163729*^9, {3.7906035349093914`*^9, 3.790603559788814*^9}, {
   3.790603643381595*^9, 3.790603788893918*^9}, {3.790604382173852*^9, 
   3.7906043836679373`*^9}, {3.7906099167924137`*^9, 3.790609963316075*^9}, {
   3.7906113123932376`*^9, 3.7906113296732264`*^9}, {3.7906612096810637`*^9, 
   3.790661222191779*^9}, 3.790661363785878*^9, {3.7906615199318085`*^9, 
   3.7906615202778287`*^9}, {3.792491833344165*^9, 3.792491839952165*^9}, {
   3.7924918840531654`*^9, 3.792492072636165*^9}, {3.792492162255165*^9, 
   3.792492175398165*^9}, {3.792492300839165*^9, 3.792492314814165*^9}, {
   3.792492688945165*^9, 3.792492699576165*^9}, {3.7924928224571652`*^9, 
   3.7924929482201653`*^9}, {3.792492996130165*^9, 3.7924930028971653`*^9}, 
   3.7924934612854705`*^9, {3.7924935647538166`*^9, 3.7924935931476555`*^9}, {
   3.7924938579031286`*^9, 3.7924938628556232`*^9}, {3.7924945577651076`*^9, 
   3.7924946295462847`*^9}, {3.79249471050238*^9, 3.792494763097639*^9}, {
   3.7924950309914255`*^9, 3.792495032045531*^9}, {3.792495786331953*^9, 
   3.792495808480953*^9}, {3.7924986568679485`*^9, 3.792498683885948*^9}, {
   3.7924992540091224`*^9, 3.79249925458318*^9}, {3.7924993219009113`*^9, 
   3.7924993348282037`*^9}, {3.792501426472003*^9, 3.7925014284721174`*^9}, {
   3.792502689914942*^9, 3.792502736256942*^9}, {3.792502775447942*^9, 
   3.792502954195942*^9}, {3.792513674265418*^9, 3.792513702108011*^9}, {
   3.792514466694743*^9, 3.7925144738181505`*^9}, {3.7925145495194798`*^9, 
   3.792514557133916*^9}, {3.7925157130750313`*^9, 3.79251572702983*^9}, {
   3.792516340842938*^9, 3.792516341965002*^9}, {3.7926732600464296`*^9, 
   3.792673268506913*^9}, 3.7926733525867224`*^9, {3.7926734483141975`*^9, 
   3.79267347702684*^9}, {3.7926736581211977`*^9, 3.792673665301609*^9}, {
   3.792674415938543*^9, 3.79267443023036*^9}, {3.7926750128866863`*^9, 
   3.792675021369171*^9}, {3.7931144784035225`*^9, 3.7931144820595226`*^9}, {
   3.7931147252935224`*^9, 3.7931147317005224`*^9}, {3.793195228863557*^9, 
   3.793195243335557*^9}, {3.7939842512814493`*^9, 3.7939842591559*^9}, 
   3.794045187735985*^9, {3.796545951019755*^9, 3.796545971880948*^9}, {
   3.7965524611073112`*^9, 3.796552468623288*^9}, {3.7973439487033424`*^9, 
   3.7973439841813717`*^9}, {3.7973440165772247`*^9, 3.7973440306490293`*^9}, 
   3.7973442331076093`*^9, 3.797344567986763*^9, {3.7973475605359273`*^9, 
   3.797347588700538*^9}, {3.7973482684864197`*^9, 3.797348274403758*^9}, {
   3.7973507481572485`*^9, 3.797350748488268*^9}, {3.803300660725988*^9, 
   3.8033007319040594`*^9}, {3.803300827747541*^9, 3.803300851701911*^9}, {
   3.803301547560712*^9, 3.8033015475697126`*^9}, {3.8033015813466444`*^9, 
   3.8033015813516445`*^9}, {3.8033016609661984`*^9, 
   3.803301660974199*^9}},ExpressionUUID->"2427d6b8-9dcc-488d-ad8a-\
1a8b9be3b01d"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"b87840f1-7d25-4002-bcb4-3829a68c1544"],

Cell[BoxData[
 RowBox[{"Column", "[", "vesplots", "]"}]], "Input",
 CellChangeTimes->{{3.792502972136942*^9, 
  3.7925029723519416`*^9}},ExpressionUUID->"a19d743e-9216-4318-9983-\
6d807b987204"],

Cell[BoxData["vesfitlist"], "Input",
 CellChangeTimes->{{3.7925029749439416`*^9, 
  3.7925029780799417`*^9}},ExpressionUUID->"4c3371c5-7d50-4b31-98b8-\
bdb9a481ca7b"],

Cell[BoxData[
 RowBox[{"veslowestelecerror", "=", 
  RowBox[{
   RowBox[{
    RowBox[{"Position", "[", 
     RowBox[{
      RowBox[{"vesfitlist", "[", 
       RowBox[{"[", 
        RowBox[{"All", ",", "2"}], "]"}], "]"}], ",", 
      RowBox[{"Min", "[", 
       RowBox[{"vesfitlist", "[", 
        RowBox[{"[", 
         RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], "]"}], "[", 
    RowBox[{"[", "1", "]"}], "]"}], "[", 
   RowBox[{"[", "1", "]"}], "]"}]}]], "Input",
 CellChangeTimes->{{3.792502220435415*^9, 3.7925022585645957`*^9}, {
  3.797347446000376*^9, 3.797347487097727*^9}, {3.7973476458538074`*^9, 
  3.797347656362408*^9}, {3.7973477131856585`*^9, 3.797347714428729*^9}, {
  3.7973477777083488`*^9, 3.7973477799004745`*^9}, {3.803300880413553*^9, 
  3.8033008906101365`*^9}},ExpressionUUID->"9c2957ff-7d42-4908-b1e3-\
c17e5e92ca46"],

Cell[BoxData[
 RowBox[{"vesfit", "=", 
  RowBox[{"Flatten", "[", 
   RowBox[{
    RowBox[{"vesfitlist", "[", 
     RowBox[{"[", 
      RowBox[{"All", ",", "1"}], "]"}], "]"}], "[", 
    RowBox[{"[", "veslowestelecerror", "]"}], "]"}], "]"}]}]], "Input",
 CellChangeTimes->{{3.7925030038399415`*^9, 3.792503025605942*^9}, 
   3.7926746072034826`*^9, {3.7974069633080406`*^9, 3.7974069657571807`*^9}, {
   3.803300897593536*^9, 
   3.8033008977985477`*^9}},ExpressionUUID->"57c4c21a-6910-4857-ac6e-\
0822d1ce2d50"],

Cell[BoxData[
 RowBox[{
  RowBox[{"vesfittedplot", "=", 
   RowBox[{"Plot", "[", 
    RowBox[{
     RowBox[{
      RowBox[{
       RowBox[{
        RowBox[{"(", 
         RowBox[{
          RowBox[{"(", 
           RowBox[{
            RowBox[{"production", "[", 
             RowBox[{"[", "1", "]"}], "]"}], "/", "vestfp"}], ")"}], 
          RowBox[{"(", 
           RowBox[{"x", "^", 
            RowBox[{"(", 
             RowBox[{"-", "a"}], ")"}]}], ")"}]}], ")"}], "^", 
        RowBox[{"(", 
         RowBox[{"1", "/", 
          RowBox[{"(", 
           RowBox[{"1", "-", "a"}], ")"}]}], ")"}]}], " ", "-", " ", 
       RowBox[{"(", 
        RowBox[{"b", " ", "a", " ", "x"}], ")"}]}], "/.", "vesfit"}], ",", 
     RowBox[{"{", 
      RowBox[{"x", ",", 
       RowBox[{"Min", "[", "dirty", "]"}], ",", 
       RowBox[{"Max", "[", "dirty", "]"}]}], "}"}], ",", 
     RowBox[{"PlotStyle", "\[Rule]", "Green"}]}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.7925030194799414`*^9, 3.7925030214229417`*^9}, {
  3.7925049667109084`*^9, 
  3.79250497390832*^9}},ExpressionUUID->"1197c130-e784-48be-bd9c-\
6b12cc82f8d5"],

Cell[BoxData[
 RowBox[{"vescomparisonplot", "=", 
  RowBox[{"Show", "[", 
   RowBox[{"originaldataplot", ",", "vesfittedplot", ",", 
    RowBox[{"Prolog", "\[Rule]", 
     RowBox[{"{", 
      RowBox[{"Inset", "[", 
       RowBox[{
        RowBox[{"Framed", "[", 
         RowBox[{
          RowBox[{"Style", "[", 
           RowBox[{"\"\<VES\>\"", ",", "14"}], "]"}], ",", 
          RowBox[{"RoundingRadius", "\[Rule]", "5"}], ",", 
          RowBox[{"Background", "\[Rule]", "White"}]}], "]"}], ",", 
        RowBox[{"Scaled", "[", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"1", "/", "2"}], ",", 
           RowBox[{"1", "-", 
            RowBox[{"1", "/", "8"}]}]}], "}"}], "]"}]}], "]"}], "}"}]}]}], 
   "]"}]}]], "Input",
 CellChangeTimes->{{3.790604439628138*^9, 3.79060445085078*^9}, {
   3.7906106558376846`*^9, 3.7906106586248446`*^9}, 3.790610780116793*^9, {
   3.7906616589187584`*^9, 3.7906616592707787`*^9}, {3.790662661120081*^9, 
   3.7906626691035376`*^9}, {3.7906643713789024`*^9, 3.7906643759131613`*^9}, 
   3.7925036616452713`*^9, 
   3.803301581356645*^9},ExpressionUUID->"8b1dcd8b-8f0b-4c82-9cfb-\
a7cce645e428"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"7df2cb84-f867-43b5-a143-b7bf00fbb7c5"]
}, Open  ]],

Cell[CellGroupData[{

Cell["Comparison", "Section",
 CellChangeTimes->{{3.7925040293942966`*^9, 
  3.7925040422530327`*^9}},ExpressionUUID->"bdf15845-a06c-43ce-b5d9-\
e46161a907ef"],

Cell[BoxData[{
 RowBox[{"GraphicsGrid", "[", 
  RowBox[{
   RowBox[{"{", 
    RowBox[{"{", 
     RowBox[{"cescomparisonplot", ",", "vescomparisonplot"}], "}"}], "}"}], 
   ",", 
   RowBox[{"ImageSize", "\[Rule]", "800"}]}], "]"}], "\[IndentingNewLine]", 
 RowBox[{"\"\<CES(fitted)\>\"", "->", "cesfit"}], "\[IndentingNewLine]", 
 RowBox[{"\[Sigma]", "\[Rule]", 
  RowBox[{"1", "/", 
   RowBox[{"(", 
    RowBox[{
     RowBox[{"1", "-", "\[Rho]"}], "/.", "cesfit"}], 
    ")"}]}]}], "\[IndentingNewLine]", 
 RowBox[{"\"\<MSE(CES)\>\"", "->", 
  "cespredelecmeansquarederror"}], "\[IndentingNewLine]", 
 RowBox[{"\"\<VES(fitted)\>\"", "->", "vesfit"}], "\[IndentingNewLine]", 
 RowBox[{
  SubscriptBox["\[Sigma]", 
   RowBox[{
    RowBox[{"C", "/", "D"}], "-", "MIN"}]], "\[Rule]", 
  RowBox[{"1", "+", 
   RowBox[{
    RowBox[{"Max", "[", 
     RowBox[{"dirty", "/", "clean"}], "]"}], " ", 
    RowBox[{
     RowBox[{"vesfit", "[", 
      RowBox[{"[", "2", "]"}], "]"}], "[", 
     RowBox[{"[", "2", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", 
 RowBox[{
  SubscriptBox["\[Sigma]", 
   RowBox[{
    RowBox[{"C", "/", "D"}], "-", "MAX"}]], "\[Rule]", 
  RowBox[{"1", "+", 
   RowBox[{
    RowBox[{"Min", "[", 
     RowBox[{"dirty", "/", "clean"}], "]"}], " ", 
    RowBox[{
     RowBox[{"vesfit", "[", 
      RowBox[{"[", "2", "]"}], "]"}], "[", 
     RowBox[{"[", "2", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", 
 RowBox[{"\"\<MSE(VES)\>\"", "->", "vespredelecmeansquarederror"}]}], "Input",
 CellChangeTimes->{{3.7906621108666086`*^9, 3.7906621506368833`*^9}, {
   3.790662209410245*^9, 3.79066223519872*^9}, {3.790662297127262*^9, 
   3.7906623081168904`*^9}, {3.7906624150770082`*^9, 
   3.7906624693161106`*^9}, {3.79066253364579*^9, 3.790662640633909*^9}, {
   3.790662675063879*^9, 3.790662712540022*^9}, {3.7906627584416475`*^9, 
   3.7906627639919653`*^9}, {3.790662918939828*^9, 3.790662942000147*^9}, {
   3.7906630164914074`*^9, 3.7906630266709895`*^9}, {3.7906630770118685`*^9, 
   3.790663082485182*^9}, {3.790664597945861*^9, 3.790664619676104*^9}, {
   3.7906647408210335`*^9, 3.7906647507956038`*^9}, {3.790664800578451*^9, 
   3.7906648080108767`*^9}, {3.7906648545065355`*^9, 
   3.7906648548795567`*^9}, {3.790664940488454*^9, 3.7906649873781357`*^9}, {
   3.790665040157154*^9, 3.790665041585236*^9}, {3.790665126150073*^9, 
   3.790665135789624*^9}, {3.790665708952407*^9, 3.790665710855516*^9}, {
   3.79067602412337*^9, 3.7906760481257453`*^9}, {3.790676147750301*^9, 
   3.7906761495963297`*^9}, {3.7925034369296694`*^9, 
   3.7925034419066644`*^9}, {3.7925050872308016`*^9, 
   3.7925050932511463`*^9}, {3.7925256365362515`*^9, 3.792525697768754*^9}, {
   3.7925273383645906`*^9, 3.7925273742376423`*^9}, {3.792527415767018*^9, 
   3.7925274375842657`*^9}, {3.792527474869398*^9, 3.792527475223418*^9}, {
   3.792527602474697*^9, 3.7925276030617304`*^9}, {3.7925285161379557`*^9, 
   3.792528577424461*^9}, {3.792529773251858*^9, 3.7925297735898776`*^9}, {
   3.797349281639369*^9, 3.7973493397396917`*^9}, {3.7973493857443233`*^9, 
   3.797349433789071*^9}, {3.7973500674643154`*^9, 3.7973500725926085`*^9}, {
   3.7974063492169166`*^9, 3.7974063498139505`*^9}, {3.797406380447703*^9, 
   3.7974063852289762`*^9}, 3.803301323359888*^9, {3.8033013760149*^9, 
   3.803301376579932*^9}, {3.8033014624058414`*^9, 3.8033014630418777`*^9}, {
   3.803301541617372*^9, 3.803301581336644*^9}, {3.8033016551408653`*^9, 
   3.803301660955198*^9}, {3.8033017133251934`*^9, 3.8033017196625557`*^9}, {
   3.8033018093286843`*^9, 
   3.803301910171452*^9}},ExpressionUUID->"526cd484-a41d-4413-ab56-\
831c0cfae179"],

Cell[" ", "Text",
 Editable->False,
 Selectable->False,
 CellFrame->{{0, 0}, {0, 3}},
 ShowCellBracket->False,
 CellMargins->{{0, 0}, {1, 1}},
 CellElementSpacings->{"CellMinHeight"->1},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellSize->{
  Inherited, 5},ExpressionUUID->"ec2185a9-f5e1-447d-9705-133d3b6267d6"]
}, Open  ]]
},
AutoGeneratedPackage->None,
Evaluator->"Local",
WindowSize->{1350, 686},
WindowMargins->{{-8, Automatic}, {Automatic, 0}},
PrivateNotebookOptions->{"VersionedStylesheet"->{"Default.nb"[8.] -> False}},
ShowSelection->True,
FrontEndVersion->"11.1 for Microsoft Windows (64-bit) (April 18, 2017)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[557, 20, 1239, 21, 163, "Text", "ExpressionUUID" -> \
"4ed25a2f-0f52-4f98-a11d-10e5720b080c"],
Cell[1799, 43, 831, 14, 50, "Input", "ExpressionUUID" -> \
"3027b843-7e91-4b81-b7d0-b4a81223ddc3"],
Cell[2633, 59, 29323, 656, 3548, "Input", "ExpressionUUID" -> \
"259456e8-d369-4206-ac46-891ef35bf721",
 InitializationCell->True],
Cell[31959, 717, 329, 10, 10, "Text", "ExpressionUUID" -> \
"2a881bf7-361e-4e5b-b511-e5cf2a8cdceb"],
Cell[CellGroupData[{
Cell[32313, 731, 235, 4, 70, "Section", "ExpressionUUID" -> \
"36e45152-e323-40ac-90fc-f53c36c5672b"],
Cell[32551, 737, 468, 10, 30, "Text", "ExpressionUUID" -> \
"49471708-c688-40d9-85c1-872f980599be"],
Cell[33022, 749, 2925, 46, 30, "Input", "ExpressionUUID" -> \
"6a1e464b-cc9f-42e8-b115-53a99b8cc120"],
Cell[35950, 797, 329, 10, 10, "Text", "ExpressionUUID" -> \
"a9773362-a590-47b8-82e7-42ca58bc953e"],
Cell[36282, 809, 1166, 25, 69, "Input", "ExpressionUUID" -> \
"66b579c3-2f4c-4c9f-b761-c513843d8189"],
Cell[37451, 836, 661, 14, 30, "Input", "ExpressionUUID" -> \
"4ad31d95-99f0-4265-a8a1-0c06c43aa446"],
Cell[38115, 852, 1401, 27, 50, "Input", "ExpressionUUID" -> \
"24bd5555-f06e-4c85-8d11-cf7e2ea83ef1"],
Cell[39519, 881, 329, 10, 10, "Text", "ExpressionUUID" -> \
"b78146b6-3b21-44c0-a790-a4dc29406b2f"]
}, Open  ]],
Cell[CellGroupData[{
Cell[39885, 896, 153, 3, 70, "Section", "ExpressionUUID" -> \
"38829f7b-b9db-4453-bc4d-183431fadd9e"],
Cell[40041, 901, 2219, 47, 145, "Input", "ExpressionUUID" -> \
"3153aff7-87fc-47ca-9f63-f2758c227b88"],
Cell[42263, 950, 329, 10, 10, "Text", "ExpressionUUID" -> \
"7871f16d-4d7a-492b-8bbd-4d040eab80ec"]
}, Open  ]],
Cell[CellGroupData[{
Cell[42629, 965, 150, 3, 70, "Section", "ExpressionUUID" -> \
"62393d1e-6487-4044-9f24-3927af8fdb15"],
Cell[42782, 970, 773, 16, 69, "Input", "ExpressionUUID" -> \
"8659ca9f-9167-4e1c-9fe7-a3fb993ddfa4"],
Cell[43558, 988, 261, 6, 30, "Input", "ExpressionUUID" -> \
"33780faa-97e8-41a5-af15-7665dd6833eb"],
Cell[43822, 996, 12374, 252, 620, "Input", "ExpressionUUID" -> \
"14262c8f-b500-45d8-85e2-8ee42f8b1799"],
Cell[56199, 1250, 329, 10, 10, "Text", "ExpressionUUID" -> \
"5edae6f4-890d-4147-a8dc-7c5fbbf41869"],
Cell[56531, 1262, 297, 5, 30, "Input", "ExpressionUUID" -> \
"93e18996-f900-417c-a0f5-7aab40656f94"],
Cell[56831, 1269, 91, 0, 30, "Input", "ExpressionUUID" -> \
"0f3c3344-f123-48e7-8676-c264b4361b91"],
Cell[56925, 1271, 801, 20, 30, "Input", "ExpressionUUID" -> \
"51b4775e-5f68-428c-8707-fe6afcd17dc3"],
Cell[57729, 1293, 660, 14, 30, "Input", "ExpressionUUID" -> \
"ff337507-7852-45dd-b24a-1e2b2abdb970"],
Cell[58392, 1309, 1596, 38, 30, "Input", "ExpressionUUID" -> \
"d52d0398-fa0e-47ee-a474-5644a25d437c"],
Cell[59991, 1349, 1204, 27, 30, "Input", "ExpressionUUID" -> \
"987b78b1-3a04-4103-aa89-66787d2db23c"],
Cell[61198, 1378, 329, 10, 10, "Text", "ExpressionUUID" -> \
"b83e1809-79c9-415f-9cd2-2d5968a4bab8"]
}, Open  ]],
Cell[CellGroupData[{
Cell[61564, 1393, 152, 3, 70, "Section", "ExpressionUUID" -> \
"0165713a-df90-41ab-b0bd-72bbdfc4ecdc"],
Cell[61719, 1398, 392, 11, 69, "Input", "ExpressionUUID" -> \
"832df3c5-0359-4715-a806-3ed2db8601af"],
Cell[62114, 1411, 261, 6, 30, "Input", "ExpressionUUID" -> \
"1fff40cd-342e-4cff-ad5e-d4023ec82cf5"],
Cell[62378, 1419, 11641, 248, 658, "Input", "ExpressionUUID" -> \
"2427d6b8-9dcc-488d-ad8a-1a8b9be3b01d"],
Cell[74022, 1669, 329, 10, 10, "Text", "ExpressionUUID" -> \
"b87840f1-7d25-4002-bcb4-3829a68c1544"],
Cell[74354, 1681, 194, 4, 30, "Input", "ExpressionUUID" -> \
"a19d743e-9216-4318-9983-6d807b987204"],
Cell[74551, 1687, 166, 3, 30, "Input", "ExpressionUUID" -> \
"4c3371c5-7d50-4b31-98b8-bdb9a481ca7b"],
Cell[74720, 1692, 849, 20, 30, "Input", "ExpressionUUID" -> \
"9c2957ff-7d42-4908-b1e3-c17e5e92ca46"],
Cell[75572, 1714, 512, 12, 30, "Input", "ExpressionUUID" -> \
"57c4c21a-6910-4857-ac6e-0822d1ce2d50"],
Cell[76087, 1728, 1125, 32, 30, "Input", "ExpressionUUID" -> \
"1197c130-e784-48be-bd9c-6b12cc82f8d5"],
Cell[77215, 1762, 1154, 27, 30, "Input", "ExpressionUUID" -> \
"8b1dcd8b-8f0b-4c82-9cfb-a7cce645e428"],
Cell[78372, 1791, 329, 10, 10, "Text", "ExpressionUUID" -> \
"7df2cb84-f867-43b5-a143-b7bf00fbb7c5"]
}, Open  ]],
Cell[CellGroupData[{
Cell[78738, 1806, 159, 3, 70, "Section", "ExpressionUUID" -> \
"bdf15845-a06c-43ce-b5d9-e46161a907ef"],
Cell[78900, 1811, 3623, 73, 164, "Input", "ExpressionUUID" -> \
"526cd484-a41d-4413-ab56-831c0cfae179"],
Cell[82526, 1886, 329, 10, 10, "Text", "ExpressionUUID" -> \
"ec2185a9-f5e1-447d-9705-133d3b6267d6"]
}, Open  ]]
}
]
*)

